package task1;

import java.util.Objects;

public class Student implements java.io.Serializable{
    private String id;
    private String name;
    private int age;

    public Student(String id, String name, int age) throws StudentIDException, StudentAgeException {
//        try {
            setId(id);
            setName(name);
            setAge(age);
//        } catch (StudentIDException e) {
//            e.printStackTrace();
//        } catch (StudentAgeException e) {
//            e.printStackTrace();
//        }
    }

    public String getId() {
        return id;
    }

    public void setId(String id) throws StudentIDException {
        if(5 != id.length()){
            throw new StudentIDException("ID异常");
        }else{
            this.id = id;
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws StudentAgeException{
        if(age >= 100 || age < 6){
            throw new StudentAgeException("年龄不合法");
        }else{
            this.age = age;
        }
    }

    @Override
    public String toString() {
        return "Student{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return Objects.equals(id, student.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
